var baseurl = "http://192.168.7.43:7002"

module.exports = {
    url:{
        login:baseurl.concat('/login'),
        user:baseurl.concat('/user'),
        dishes:'/dishes', 
        createOrder:'/createOrder',
        orderRecord:'/orderRecord',
        recordDetail:'/recordDetail'
    },
    GET:GET,
    POST:POST
}

var requestHandler = {
    url:'',
    params:{},
    success: function(res){
         // success 
    }, 
    fail: function() {
         // fail 
    }, 
}
 //GET请求 
function GET(requestHandler) {
    request('GET',requestHandler) 
} 
//POST请求 
function POST(requestHandler) { 
    request('POST',requestHandler) 
} 
function request(method,requestHandler) {
    //注意：可以对params加密等处理 
    var params = requestHandler.params;
    var URL = baseurl.concat(requestHandler.url) 
    wx.request({
        url: URL, 
        data: params, 
        method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // 
        header: {}, // 设置请求的 header 
        success: function(res){ //注意：可以对参数解密等处理
            if(res.data.code === 200){
                requestHandler.success(res.data.data) 
            }else{
                requestHandler.fail()
            } 
        }, 
        fail: function() { 
            requestHandler.fail() 
        }, 
        complete: function() {
             // complete 
        } 
    }) 
}

